package com.pkche.core.advanced.util;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Application Lifecycle Listener implementation class SessionScanner
 *
 */
public class SessionScanner implements HttpSessionListener {

   public static Map<String, HttpSession> sessions = new HashMap<String, HttpSession>();
    private Object locket=new Object();
    
	/**
     * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
     */
    public void sessionCreated(HttpSessionEvent se) {
    	
    	synchronized (locket) {  
    		sessions.put(se.getSession().getId(), se.getSession());
    	}

    }

	/**
     * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
     */
    public void sessionDestroyed(HttpSessionEvent se) {
    	synchronized (locket){
    		sessions.remove(se.getSession().getId());
    	}
    	
    }
	
}
